package com.mlk.repair.controller;

import com.mlk.busPram.po.EngBusParam;
import com.mlk.busPram.service.BusParamService;
import com.mlk.core.component.page.Pager;
import com.mlk.core.util.ServerResponse;
import com.mlk.repair.po.EngRepairTicket;
import com.mlk.repair.po.EngRepairTicketItem;
import com.mlk.repair.service.EngRepairService;
import com.mlk.repair.vo.EngRepairTicketVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/eng/repair")
public class EngRepairController {

    @Resource
    private EngRepairService engRepairService;

    @Resource
    private BusParamService busParamService;

    /**
     * 返回首页
     * @return
     */
    @RequestMapping("index")
    public String index(){
        return "repair/repair";
    }

    /**
     * 分页展示数据内容
     * @return
     */
    @ResponseBody
    @RequestMapping("listPage")
    public Pager listPage(EngRepairTicketVO vo){
        return this.engRepairService.listPage(vo);
    }

    /**
     * 接收报备单
     * @return
     */
    @ResponseBody
    @RequestMapping("accept")
    public ServerResponse accept(EngRepairTicket ticket){
        return this.engRepairService.accept(ticket);
    }

    /**
     * 完成报备
     * @return
     */
    @RequestMapping("finish")
    @ResponseBody
    public ServerResponse finish(EngRepairTicket ticket){
        return this.engRepairService.finish(ticket);
    }

    /**
     * 添加到业务参数
     * @return
     */
    @ResponseBody
    @RequestMapping("addParam")
    public ServerResponse addParam(EngBusParam param){
        return this.busParamService.add(param);
    }

    /**
     * 校正ticket的内容
     * @return
     */
    @RequestMapping("just")
    @ResponseBody
    public ServerResponse just(EngRepairTicketItem ticket){
        return this.engRepairService.just(ticket);
    }

    /**
     * 检验能否结束报备单
     * @return
     */
    @ResponseBody
    @RequestMapping("checkTicketCanComplete")
    public ServerResponse checkTicketCanComplete(String ticketId){
        return this.engRepairService.checkTicketCanComplete(ticketId);
    }

    /**
     * 进入到明细页面
     * @param id
     * @return
     */
    @RequestMapping("lookDetail")
    public String lookDetail(Integer id, Model model){
        model.addAttribute("id",id);
        model.addAttribute("data",this.engRepairService.findAllInfoOfRepair(id));
        return "repair/detail";
    }
}
